<?php

use yii\helpers\Url;
use common\models\Word;

?>
<?php echo $this->render("/layouts/top")?>


<style>

.questiondiv{


	margin:0px auto; 
	margin-top:1px; 
	width:1000px; 

	line-height:28px; 
	background-color:#EEE;

}

.questiondiv span{

	
}

ul{margin:0;padding:0;list-style:none;}  


.rightnum{
	display:inline-block;
	padding:0px;
	width:50px; 
	height:28px; 
	font-size:18px;
	text-align:center;
}


</style>
<script type="text/javascript" src="/js/NoLimitCategory.js"></script>
<div style="margin:0px auto; width:1000px; margin-bottom:10px;">
    <div>毕业/破冰/总量：<?php echo $graduatedcount." / ".$icebreaking." / ".$allword?></div>
</div>

<div style="margin:0px auto; width:1000px; margin-bottom:10px;">
  <div>进行/未破：<?php echo ($icebreaking-$graduatedcount)." / ".($allword-$graduatedcount)?></div>
</div>
<div style="margin:0px auto; width:1000px; margin-bottom:10px;"><!--
--><div style="display:inline-block; margin-left:5px; font-size:12px; vertical-align:top; width:65px; height:24px; padding-left:5px; background:#F0F0F0">
    <div style="display:inline-block; height:24px; line-height:24px;">显示全部</div><!--
 --><div style="display:inline-block; height:24px; line-height:24px; vertical-align:top; position:relative">
      <input id="graduated" type="checkbox"<?php if($graduated == 0)echo ' checked="checked"'?> style="position:absolute; top:6px" />
    </div><!--
--></div><!--
-->
</div>
<div style="margin:0px auto; width:1000px; margin-bottom:10px; font-size:14px">英文：
  <input id="searchtext" type="text" value="<?php echo $searchtext?>" style=" width:160px; height:20px;"/>
</div>
<div style="margin:0px auto; width:1000px; margin-bottom:10px; font-size:14px">翻译：
  <input id="transtext" type="text" value="<?php echo $transtext?>" style=" width:160px; height:20px;"/>
</div>
<div style="margin:0px auto; width:1000px; margin-bottom:10px;"><!--
--><div style="display:inline-block; margin-left:0px;"><input type="button" value="查找" onclick="search()" style=" width:50px; height:24px;"/></div>
</div>
<?php

//pre($favorite);
	for($i=0; $i<count($favorite); $i++){

		$cname1 = empty($favorite[$i]["cname"]) ? "" : "[".$favorite[$i]["cname"]."]";
		$cname2 = empty($favorite[$i]["cname2"]) ? "" : "[".$favorite[$i]["cname2"]."]";
		$cname3 = empty($favorite[$i]["cname3"]) ? "" : "[".$favorite[$i]["cname3"]."]";
		$cname4 = empty($favorite[$i]["cname4"]) ? "" : "[".$favorite[$i]["cname4"]."]";
		$cname5 = empty($favorite[$i]["cname5"]) ? "" : "[".$favorite[$i]["cname5"]."]";
		
		$word = empty($favorite[$i]["word"]) ? "" : $favorite[$i]["word"];
		$ipa_en = empty($favorite[$i]["ipa_en"]) ? "" : stripcslashes($favorite[$i]["ipa_en"]);
		$ipa_us = empty($favorite[$i]["ipa_us"]) ? "" : stripcslashes($favorite[$i]["ipa_us"]);
		$trans = empty($favorite[$i]["trans"]) ? "" : $favorite[$i]["trans"];
		

		$correct = $favorite[$i]["express_correct"];

		$color = \common\components\Common::getRightColor($correct);

		
		$curtime = time();
		
		$last_right_time = $favorite[$i]["express_correct_at"];

		$locktime = \common\components\Common::getLocktime($correct);
		
		if($last_right_time+$locktime > $curtime){
			$questioncolor = '#BBB';
		}else{
			$questioncolor = '#000';
		}
		
		$trans_arr = explode('|', $trans);
		$question = empty($favorite[$i]["question"]) ? Word::getTransStr($trans_arr) : $favorite[$i]["question"];

		if(!empty($favorite[$i]["answer"])){
			$answer = $favorite[$i]["answer"];
		}else{
			$answer = '<a href="'.Url::to(['/word/detail', 'id'=>$favorite[$i]["id"]]).'"><h1>'.$word.'</h1></a>';
			
			if(!empty($ipa_en)){
				$answer .= '英<span style="font-family:lucida sans unicode, arial, sans-serif;">'.stripcslashes($ipa_en).'</span>';
			}
			
			if(!empty($ipa_us)){
				$answer .= '　美<span style="font-family:lucida sans unicode, arial, sans-serif;">'.stripcslashes($ipa_us).'</span>';
			}
			
			$trans_str = '';
			if(count($trans_arr) > 0){
				$trans_str = implode('<br>', $trans_arr);
				$answer .= '<br><br>'.$trans_str;
			}

		}

?>

<div class="questiondiv">
  <span style="display:inline-block; width:50px; text-align:center"><?php echo $favorite[$i]["id"]?></span>  
  
  <span style="display:inline-block; width:820px; color:<?php echo $questioncolor?>;">
  <?php echo $question?>
  </span>
  <span class="rightnum"><strong style="color:<?php echo $color?>;"><?php echo $correct?></strong></span>
  <span style="display:inline-block; width:50px; text-align:center;"><input type="button" value="答案" onclick="seeanswer(this)" /></span>  
</div>

<div style="margin:0px auto; width:1000px;display:none">
  <div style="padding:4px;">
  <?php echo $answer?>
  </div>
  <div style="margin:0px auto; width:100%; text-align:center; padding:4px; padding-bottom:8px;">
    <input type="button" value="收起答案" onclick="closeanswer(this)"/> 
    <input type="button" value="编辑知识" onclick="edit(<?php echo $favorite[$i]["id"]?>)"/>
    <input type="button" value="顺序升一" onclick="exchangeAbove(<?php echo $favorite[$i]["id"]?>)"/> 
    <input type="button" value="顺序放后" onclick="orderlast(<?php echo $favorite[$i]["id"]?>)"/> 
    <input type="button" value="降低级别" onClick="express_wrong(<?php echo $favorite[$i]["id"]?>)"/>
    <input type="button" value="回答正确" onclick="express_correct(<?php echo $favorite[$i]["id"]?>)"/>
  </div>
</div>
<?php
	}
?>

<br>

<?php
	$pageurl = "?searchtext=$searchtext&transtext=$transtext&graduated=$graduated&page=";
	
?>
<div style=" margin:0px auto; width:1000px; height:28px; line-height:28px; background-color:#EEE; text-align:center">
<span>总数据:<?php echo $pv->dataCount?>条</span>
<a href="<?php echo $pageurl."1"?>">首页</a>
<a href="<?php echo $pageurl.$pv->prevPage?>">上一页</a>
<span><?php echo $pv->currentPage."/".$pv->pageCount?></span>
<a href="<?php echo $pageurl.$pv->nextPage?>">下一页</a>
<a href="<?php echo $pageurl.$pv->pageCount?>">末页</a>
</div>

<script language="javascript">

var page = <?php echo $pv->currentPage;?>;




function search(){
	var searchtext = $('#searchtext').val();
	var transtext = $('#transtext').val();
	var graduated = ($('#graduated').is(':checked')) ? 0 : 1;//0显示全部，1只显示未毕业的

	var pageurl = "?"+"searchtext="+encodeURIComponent(searchtext)+"&transtext="+encodeURIComponent(transtext)+"&graduated="+graduated+"&page="+page;

	window.location.href = pageurl;

}

function seeanswer(obj){

	var div = $(obj).parent().parent().next();

	var h = div.height();

	div.css('display', 'block');
	div.css('height', '0px');
	
	div.animate({height:h}, 500);

}

function closeanswer(obj){
	var div = $(obj).parent().parent();
	var h = div.height();
	
	div.animate({height:'0px'}, 500, function(){
		div.css('display', 'none');
		div.height(h);//重新给它高度，否则下次展开的时候不灵，因为展开的时候这个高度需要读出来
	});
}

function edit(kid){
	window.location.href = "<?php echo Url::to(['/english/edit'])?>"+"?id="+kid;
}

function orderlast(id){
	
	if(confirm("确定降序？")){
		new Ajax().get({
			url : "<?php echo Url::to(['/practice/async-last'])?>"+"?id="+id,
			resultType : 'json',
			onLoaded : function(result){
				if(result.code == 1){
					alert("成功");
					window.location.reload();
				}else{
					alert(result.info);
				}
			}
							
		});
	}

}

function exchangeAbove(id){
	
		new Ajax().get({
			url : "<?php echo Url::to(['/practice/async-exchange-above'])?>"+"?id="+id,
			resultType : 'json',
			onLoaded : function(result){
				if(result.code == 200){
					alert("成功");
					window.location.reload();
				}else{
					alert(result.info);
				}
			}
							
		});

}

//理解模式回答正确
function express_correct(eid){
    console.log(eid);

    $.ajax({
        url : "<?php echo Url::to(['/practice/express-correct'])?>",
        type : "GET",
        data : {
            eid : eid,
        },
        dataType : "json",
        success : function (result) {
            console.log(result);
            if(result.code == 200){
                alert("成功");
                window.location.reload();
            }else{
                alert(result.info);
            }
        }
    });

}

//理解模式回答错误
function express_wrong(eid){

    $.ajax({
        url : "<?php echo Url::to(['/practice/express-wrong'])?>",
        type : "GET",
        data : {
            eid : eid,
        },
        dataType : "json",
        success : function (result) {
            console.log(result);
            if(result.code == 200){
                alert("成功");
                window.location.reload();
            }else{
                alert(result.info);
            }
        }
    });

}

</script>
<br>
<?php echo $this->render("/layouts/footer")?>
